//
// class that manager geometric entities to compose a complete frame
//////////////////////////////////////////////////////////////////////////

#ifndef ACMFRAME_H
#define ACMFRAME_H

#include <stdio.h>
#include <stdlib.h>

#include "geometry/curves/curvefactory.h"
#include "vertex.h"

class Curve;

//
//////////////////////////////////////////////////////////////////////////
class acmFrame
{

public:
  acmFrame ( );
  ~acmFrame( );

  // read/write file
  bool read  (char *name);
  bool write (char *name);

  //
  void clear ();

  // set object draw
  void setDraw (drawGRA *objdraw);

  void getMaxMin( double *xmin, double *xmax, double *ymin, double *ymax);

  // draw current model using current object draw
  void draw ( );

  bool pick (double x, double y, bool add, double tol);

  void addCurve (Curve *cv);

private:
  
  void drawCurves   ( );
  void drawVertices ( );


  // read curves
  bool readGeometry   (FILE *fl);
  void readCurveAttr  (FILE *ptr_file);
  void readVertexAttr (FILE *ptr_file);

  // find label in file
  int nextLabel (FILE *f,  char *label );
  int findCurve (FILE *fp);
  int nextAttribute(FILE *fp, char *label );

  // read a curve
  int readCurve (FILE *f, Curve::ECurveType _type);
  
  // read Vertex
  int readVertex (FILE *f);

  // read global parameters
  int readGlobalParameters (FILE *f);

  // pick code
  void pickCode (double x, double y, double xmin, double xmax, 
                 double ymin, double ymax, int code[4]);
  bool pickPolyline (vector <Point3D> &poly, double x, double y, double tol);


  // list of curves
  vector <Curve *> m_curves;
  // list of vertices
  vector <vertex *> m_vertices;

  // object draw
  drawGRA *m_objdraw;

};

#endif // ACMFRAME_H
